package aad.storyboard.model;

import android.graphics.Paint;

public class FadeAnimation extends Animation{
	

	private static Paint mForeGroundPaint;
	 private static Image icurrentCharacter;   
     
    private static int foregrndalpha = 0;    
    private boolean toAlpha;
    private int targetAlpha;

    public FadeAnimation(int startTime,int duration, boolean toAlpha, int targetAlpha)  
    {  
    	super(duration, startTime);
    	this.duration=duration;
    	this.targetAlpha=targetAlpha;
   
    	mForeGroundPaint = new Paint();
    	for (Image i: images)
    	{
    		i.setPaint(mForeGroundPaint);
    	}
    	//icurrentCharacter=images.get(0);    	
    	//icurrentCharacter.setPaint(mForeGroundPaint);
    	
    	this.toAlpha=toAlpha;
    	if (toAlpha)foregrndalpha=255;
    	else foregrndalpha=0;
    	
    }
    
    @Override
	public void animate() {			
    	
    	
    	if (toAlpha)	        {
    		
	        	
	        	if(foregrndalpha > targetAlpha)  
	        	{  
	        		System.out.println("targetalpha");
	        		foregrndalpha -= 5;          
	        		mForeGroundPaint.setAlpha(foregrndalpha);
	        		for (Image i:images)i.getPaint().setAlpha(foregrndalpha);
	        	    
	        	}  
	   }
    	
	        else 
	        {  
	        	System.out.println("FadeAnimation triggered"+foregrndalpha+toAlpha);
	        	if(foregrndalpha < targetAlpha)
	        	{  
	        		foregrndalpha += 5;          
	        		mForeGroundPaint.setAlpha(foregrndalpha);	
	        		for (Image i:images)i.getPaint().setAlpha(foregrndalpha);
	        		System.out.println("FadeAnimation triggered"+foregrndalpha);
	        	}
	  	        
	  	    }          
	        
	}
	      

	@Override
	public void undo() {
		if (toAlpha)mForeGroundPaint.setAlpha(255);
		else mForeGroundPaint.setAlpha(0);
		
	}

	@Override
	public void adjustParameters() {
		// TODO Auto-generated method stub
		
	}


}
